package clientGUI;

import java.awt.Dimension;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import java.awt.Color;
import javax.swing.ImageIcon;
import javax.swing.JComboBox;
import javax.swing.border.LineBorder;

/**
 * @author Shay
 * Creating Login GUI
 */
public class LoginPanel extends JPanel {
	
	private static final long serialVersionUID = 1L;
	public JTextField textFieldLogin;
	public JPasswordField passwordField;
	public JButton btnSubmit;
	JComboBox<String> comboBox_1;
	/**
	 * Create the panel the login.
	 */
	public LoginPanel() {
		setBorder(new LineBorder(new Color(0, 0, 0), 3, true));
		setLayout(null);
		setPreferredSize(new Dimension(644, 462));
		JLabel lblWelcomeTo = new JLabel("Welcome To OBL");
		lblWelcomeTo.setForeground(new Color(0, 0, 0));
		lblWelcomeTo.setFont(new Font("Tahoma", Font.BOLD, 45));
		lblWelcomeTo.setBounds(120, 13, 396, 82);
		add(lblWelcomeTo);
		
		JLabel lblLogin = new JLabel("Username :");
		lblLogin.setFont(new Font("Tahoma", Font.PLAIN, 20));
		lblLogin.setBounds(199, 124, 122, 48);
		add(lblLogin);
		
		textFieldLogin = new JTextField();
		textFieldLogin.setBounds(333, 141, 86, 20);
		add(textFieldLogin);
		textFieldLogin.setColumns(10);
		
		JLabel lblPassword = new JLabel(" Password :");
		lblPassword.setFont(new Font("Tahoma", Font.PLAIN, 20));
		lblPassword.setBounds(199, 171, 106, 25);
		add(lblPassword);
		
		passwordField = new JPasswordField();
		passwordField.setBounds(332, 174, 87, 20);
		add(passwordField);
		
		btnSubmit = new JButton("Submit");
		btnSubmit.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) 
			{
				String[] s=new String[3];
				s[0]="Login";
				s[1]=textFieldLogin.getText();
				s[2]=new String(passwordField.getPassword());
				MainGUI.OBLClient.ClientID=s[1];
				MainGUI.OBLClient.handleMessageFromClient(s);
				
			}
		});
		btnSubmit.setBounds(246, 219, 142, 41);
		add(btnSubmit);
		JLabel label_1 = new JLabel("");
		label_1.setIcon(new ImageIcon("images/test35.jpg"));
		label_1.setBounds(3, 3, 638, 456);
		add(label_1);
	}
	/**
	 * The function do log in.
	 */
	public void dolog()
	{
		String[] s=new String[3];
		s[0]="Login";
		s[1]=textFieldLogin.getText();
		s[2]=new String(passwordField.getPassword());
		MainGUI.OBLClient.ClientID=s[1];
		MainGUI.OBLClient.handleMessageFromClient(s);
	}
}
